<?php
require_once ("src/db/connectdatabase.php");

function loadinfodealer($email) {
	$con = new ConnectDB();
	
	$sql = "SELECT r.regis_name, r.gender, r.dayofbirth, r.mobile, r.homephone, r.address, r.province, r.companywork, r.addresswork, r.introinfowork, r.introinfokinhnghiem, r.cardnumber, r.bankid, b.bankname, r.idcode FROM registrationbank AS r, banks AS b WHERE r.bankid=b.bankid AND r.regis_email='".$email."' AND r.isaccept=true AND r.islock=false";
	return $con -> getvalueString($sql);
}

function loadSumSalaryMonth($email, $date) {
	$con = new ConnectDB();
	
	$sql = "SELECT amount1,amount3,namecustomer FROM profilecustomer WHERE regis_email='".$email."' AND datecreate>=".$date;
	return $con -> getvalueString($sql);
}

function getIntroProfile() {
	$con = new ConnectDB();
	$tbl = " loan_intro_footer";
	$fn = array('header', 'footer');
	$condetion = array('id' => 'info-profile-dealer');
	return $con -> getvalue($tbl, $fn, $condetion);
}
$intropro = getIntroProfile();

function int_to_date($int)
{
    $time  = date("d-m-Y", $int);
    return $time;
}

function int_to_date2($int)
{
    $time  = date("d/m/Y H:i", $int);
    return $time;
}


if(!isset($_SESSION['taichinhondealer'])) {
?>
<script>
window.location = '<?php echo($host) ?>dang-nhap.html';
</script>
<?php
} else {
	$userdealer = $_SESSION['taichinhondealer'];
	
	//load sum salary acc
	$now = getdate(); 
	$monthDate = "01-" . $now["mon"] . "-" . $now["year"];
	$monthDate = strtotime($monthDate);
	$arrsalary = loadSumSalaryMonth($userdealer, $monthDate);
	$sumsalary = 0;
	foreach($arrsalary as $entry) {
		$sumsalary = $sumsalary + $entry[1];
	}
	$sumsalary = changnumbermoney($sumsalary);
	
	//load info acc
	$arracc = loadinfodealer($userdealer);
	if(count($arracc) > 0) {
?>
<script type="text/javascript">
    document.title = "Tài khoản đăng nhập <?php echo($arracc[0][0]) ?>";
</script>
<style>
.menu-album {
	width: 100%;
	border-radius: 5px 5px 5px 5px;
	background-color: #FFF;
	border-top: solid 1px #D7D7D7;
	box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.05);
	min-height: 50px;
}
.menu-album .menualbumleft {
	position: relative;
	min-width: 600px;
	height: 20px;
	float: left;
	margin-left: -20px;
}

.menu-album .menualbumleft ul {
	margin: 10px 0px 10px 0px;
}
.menu-album .menualbumleft ul li:hover {
	height: 20px;
	border-color:#687582;
	cursor: pointer;
}

.menu-album .menualbumleft ul li {
    border-bottom: 1px solid #FAFAFA;
    height: 20px;
    list-style: none outside none;
    overflow: hidden;
    padding: 3px;
	text-align: center;
	display: block;
	float: left;
	padding-top: 5px;
	padding-left: 15px;
	padding-right: 15px;
	box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.05);
	border-color: #D7D7D7;
	border-style: solid;
	border-width: 1px;
	background-color: #F4F4F4;
	font-weight:600;
	cursor: pointer;
}

.menu-album .menualbumleft ul li.first {
	border-radius: 3px 0px 0px 3px;
}

.menu-album .menualbumleft ul li.last {
	border-radius: 0px 3px 3px 0px;
}

.menu-album .menualbumleft ul li.selected {
	height: 20px;
	background: none repeat scroll 0 0 #E0E0E0;
}

.content-profile {
	width: 980px;
	min-height: 150px;
	margin-top: 20px;
}

.info-left, .info-right {
	float: left;
	width: 490px;
}

.member-info-basic .info-link-edit {
	margin-top: 10px;
	font-size: 12px;
}
.member-info-basic .info-link-edit a, .member-info-basic table a {
	text-decoration: none;
	color: #00F;
}

.member-info-basic .info-link-edit a:hover, .member-info-basic table a:hover {
	text-decoration: underline;
}

.info-left .member-info-basic {
	border: thin groove #C4CDE2;
	margin-left: 20px;
	margin-right: 20px;
	border-top-left-radius: 4px;
	border-top-right-radius: 4px;
	border-bottom-left-radius: 4px;
	border-bottom-right-radius: 4px;
	background-color: #FFF;
	margin-bottom: 30px;
	padding-bottom: 15px;
}

.member-info-basic table {
	font-size: 14px;
}

.info-member-title h1 {
	font-size: 18px;
	font-weight: 700px;
}

.info-right .member-info-basic {
	border: thin groove #C4CDE2;
	margin-left: 20px;
	margin-right: 20px;
	border-top-left-radius: 4px;
	border-top-right-radius: 4px;
	border-bottom-left-radius: 4px;
	border-bottom-right-radius: 4px;
	background-color: #FFF;
	margin-bottom: 30px;
	padding-bottom: 15px;
}

.title-color-blue {
	height: 5px;
	border-top-left-radius: 2px;
	border-top-right-radius: 2px;
	background-color: #76A7FA;
}

.info-basic-bold {
	font-weight: 700;
	padding-right: 10px;
	width: 130px;
}

.showms {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: smaller;
	font-style: italic;
	color: #FF0000;
}
</style>
<link rel="stylesheet" type="text/css" href="<?php echo($host) ?>css/jquery-ui.css">
<script src="<?php echo($host) ?>js/jquery-ui.js"></script>
<script type="text/javascript" src="<?php echo($host) ?>js/jquery-uicaledate.js"></script>
<div class="text12" style="margin: auto; width: 970px; height: 11px; margin-top: 11px; color: #0a8bd9;">
	<u><a href="#" class="text12" style="color: #0080d6;">Trang Chủ</a></u>&gt; Tài khoản <?php echo($arracc[0][0]) ?>
</div>
<div style="clear:both; height:15px;"><input type="hidden" id="cont-page" value="<?php if(isset($_GET['ac'])) { echo($_GET['ac']); } ?>" /></div>
<div class="intrl_txt">
	<div class="menu-album">
        <div class="menualbumleft">
            <ul>
	            <li class="first canhanpage">THÔNG TIN CÁ NHÂN</li>
                <li class="thongbaopage-click">THÔNG BÁO</li>
    	        <li class="last hosocuabanpage">TẤT CẢ HỒ SƠ ĐÃ LOGIN</li>
            </ul>
        </div>
   	</div>
    
    <div class="content-profile">
    	<?php
			if(isset($_GET['ac'])) {
				$pageac = $_GET['ac'];
				if($pageac == "ho-so-cua-ban") {
					include("recordsofdealer.php");
				} else if($pageac == 'chi-tiet-ho-so') {
					include("profiledetail.php");
				} else if($pageac == 'ca-nhan') {
					include("profileinfo.php");
				} else if($pageac == "thong-bao") {
					include("profileadvertise.php");
				} else if($pageac == "chi-tiet-thong-bao") {
					include("detailadvertise.php");
				} else {
					include("recordsofdealer.php");
				}
			} else {
				include("recordsofdealer.php");
			}
		?>
    </div>
</div>
<script>
$(document).ready(function(e) {
    $('.canhanpage').click(function(e) {
        window.location = '<?php echo($host) ?>profile/ca-nhan.html';
    });
	
	$('.hosocuabanpage').click(function(e) {
        window.location = '<?php echo($host) ?>profile/ho-so-cua-ban.html';
    });
	
	$('.thongbaopage-click').click(function(e) {
        window.location = '<?php echo($host) ?>profile/thong-bao.html';
    });
	
	var pagename = $('#cont-page').val();
	if(pagename == "ca-nhan") {
		$('.canhanpage').addClass('selected');
	} else if(pagename == "thong-bao") {
		$('.thongbaopage-click').addClass('selected');
	} else if(pagename == "chi-tiet-thong-bao") {
		$('.thongbaopage-click').addClass('selected');
	} else {
		$('.hosocuabanpage').addClass('selected');
	}
});
</script>
<?php	
	} else {
		session_destroy();
		?>
		<script>
	        window.location = '<?php echo($host) ?>dang-nhap.html';
        </script>
        <?php
	}
}
?>